# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=crcmod
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}"  "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.7
pkgrel=1
pkgdesc="Cyclic Redundancy Check (CRC) implementation in Python. (mingw-w64)"
arch=('any')
url="https://pypi.python.org/pypi/crcmod/"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
options=('staticlibs' 'strip' '!debug')
source=("https://pypi.python.org/packages/source/c/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('dc7051a0db5f2bd48665a990d3ec1cc305a466a77358ca4492826f41f283601e')

prepare() {  
  cd "${srcdir}"
  for pver in {2,3}; do 
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_realname}-${pkgver}" "python${pver}-build-${CARCH}"
  done  
}  
  
build() {
  cd "${srcdir}"
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done  
}

package_python3-crcmod() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
}

package_python2-crcmod() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
}

package_mingw-w64-i686-python2-crcmod() {
  package_python2-crcmod
}

package_mingw-w64-i686-python3-crcmod() {
  package_python3-crcmod
}

package_mingw-w64-x86_64-python2-crcmod() {
  package_python2-crcmod
}

package_mingw-w64-x86_64-python3-crcmod() {
  package_python3-crcmod
}
